package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.BaseDepartDao;
import ysq.xyg.model.BaseDepart;
import ysq.xyg.service.BaseDepartService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-04-19 14:11
 **/
@Service("baseDepartService")
public class BaseDepartServiceImpl extends BaseServiceImpl<BaseDepart> implements BaseDepartService {
    @Resource
    private BaseDepartDao baseDepartDao;
    @Autowired
    public void setBaseDepartDao(BaseDepartDao baseDepartDao) {
        this.baseDao = baseDepartDao;
    }

    //分页查询
    public PageInfo<BaseDepart> pageInfo(BaseDepart baseDepart, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        Example example = new Example(BaseDepart.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(baseDepart.getDepartname())){
            criteria.andLike("departname","%"+baseDepart.getDepartname()+"%");
        }
        if(StringUtil.isNotEmpty(baseDepart.getRemovetag())){
            criteria.andEqualTo("removetag",baseDepart.getRemovetag());
        }
        List<BaseDepart> list=baseDepartDao.selectByExample(example);
        return new PageInfo<BaseDepart>(list);
    }

    //条件查询
    public List<BaseDepart> list(BaseDepart baseDepart) {

        Example example = new Example(BaseDepart.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(baseDepart.getDepartname())){
            criteria.andLike("departname","%"+baseDepart.getDepartname()+"%");
        }
        if(StringUtil.isNotEmpty(baseDepart.getRemovetag())){
            criteria.andEqualTo("removetag",baseDepart.getRemovetag());
        }
        List<BaseDepart> list=baseDepartDao.selectByExample(example);
        return list;
    }
}
